﻿// Example header text. Can be configured in the options.
using System.Collections;

namespace vtech_frameWorks.Library
{
    public class ClsLocalSettings
    {
        // Fields
        //private static string _ConnectString = "";
        private Hashtable _HtData;
        public string _NumbericFormatString = "";
        public bool AutoLogin = true;
        public string DB_ConnectionString = "";
        public string DB_Name = "";
        public string DB_Pass = "";
        public string DB_Server = "";
        public string DB_UID = "";
        public bool SaveLog;
        public string HardwareID = "";
        //public static ClsLocalSettings Setting = LoadFromFile();
        public static bool NeedReloadConnectString = true;
        public string Password = "";
        public string SerialKey;
        public string SoMay = "";
        public string UserName = "";
        public bool UseExpertMode;

        // Methods
        //public static ClsLocalSettings LoadFromFile()
        //{
        //    try
        //    {
        //        if (File.Exists(Application.StartupPath + @"\Settings.vtech"))
        //        {
        //            StreamReader reader = new StreamReader(Application.StartupPath + @"\Settings.vtech");
        //            string cipherString = reader.ReadToEnd();
        //            reader.Close();
        //            MemoryStream serializationStream = new MemoryStream(ClsCommonLib.DecryptStringToBytes(cipherString, "vtech_frameWorks"));
        //            object obj2 = new BinaryFormatter().Deserialize(serializationStream);
        //            if (obj2 == null)
        //            {
        //                return new ClsLocalSettings();
        //            }
        //            return (ClsLocalSettings)obj2;
        //        }
        //        return new ClsLocalSettings();
        //    }
        //    catch
        //    {
        //        return new ClsLocalSettings();
        //    }
        //}

        //public void SaveToFile()
        //{
        //    try
        //    {
        //        string path = Application.StartupPath + @"\Settings.vtech";
        //        if (File.Exists(path))
        //        {
        //            File.Delete(path);
        //        }
        //        MemoryStream serializationStream = new MemoryStream();
        //        new BinaryFormatter().Serialize(serializationStream, this);
        //        string str2 = ClsCommonLib.EncryptBytesToString(serializationStream.GetBuffer(), "vtech_frameWorks");
        //        StreamWriter writer = new StreamWriter(path);
        //        writer.Write(str2);
        //        writer.Close();
        //        NeedReloadConnectString = true;
        //    }
        //    catch
        //    {
        //    }
        //}

        // Properties
        //public static string ConnectString
        //{
        //    get
        //    {
        //        if (NeedReloadConnectString)
        //        {
        //            ClsLocalSettings settings = LoadFromFile();
        //            if (settings.UseExpertMode)
        //            {
        //                _ConnectString = settings.DB_ConnectionString;
        //            }
        //            else
        //            {
        //                _ConnectString = string.Format("SERVER = {0}; DATABASE = {1}; UID= {2}; PWD={3}", new object[] { settings.DB_Server, settings.DB_Name, settings.DB_UID, settings.DB_Pass });
        //            }
        //            NeedReloadConnectString = false;
        //        }
        //        return _ConnectString;
        //    }
        //    set
        //    {
        //        _ConnectString = value;
        //    }
        //}

        public object this[string key]
        {
            get
            {
                if (this._HtData == null)
                {
                    this._HtData = new Hashtable();
                    return null;
                }
                if (this._HtData.ContainsKey(key))
                {
                    return this._HtData[key];
                }
                return null;
            }
            set
            {
                if (this._HtData.ContainsKey(key))
                {
                    this._HtData[key] = value;
                }
                else
                {
                    this._HtData.Add(key, value);
                }
            }
        }

        public string NumbericFormatString
        {
            get
            {
                return "### ### ### ### ###";
            }
            set
            {
                this._NumbericFormatString = value;
            }
        }
    }
}